#!/usr/bin/python2.4
#
#Copyright 2009 Google Inc.
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
#


"""Tests for the module sorting_column_sets."""

import logging
import unittest
import sorting_column_sets


class SortingColumnSetsTest(unittest.TestCase):
  """Tests the module sorting_column_sets."""

  def setUp(self):
    """Set up method."""
    logging.info('TEST: ' + self.id())
    self.set_manager = sorting_column_sets.SetManager()

  def tearDown(self):
    """Tear down method."""
    self.set_manager.Clear()

  def testSetManagerSingleton(self):
    """Tests Singleton implementation of SetManager class."""
    self.set_manager.UpdateColumnSets('1', 'level1', 'level2', 'level3')
    set_manager1 = sorting_column_sets.SetManager()
    self.assertEqual(len(set_manager1.GetUniqueValues(1)),
                     len(self.set_manager.GetUniqueValues(1)))
    self.assertEqual(len(set_manager1.GetUniqueValues(2)),
                     len(self.set_manager.GetUniqueValues(2)))
    self.assertEqual(len(set_manager1.GetUniqueValues(3)),
                     len(self.set_manager.GetUniqueValues(3)))

  def testUpdateColumnSets(self):
    """Tests the method UpdateColumnsets."""
    self.set_manager.UpdateColumnSets('1', 'level1', 'level2', 'level3')
    self.set_manager.UpdateColumnSets('2', 'level1', 'level2_new', 'level3_new')
    self.set_manager.UpdateColumnSets('3', 'level1', 'level2_3', 'level3_3')
    self.set_manager.UpdateColumnSets('4', 'level1', 'level2_3', 'level3_4')
    values = self.set_manager.GetUniqueValues(1)
    self.assertEqual(len(values), 1)
    self.assertEqual(values[0], 'level1')

    values = self.set_manager.GetUniqueValues(2)
    self.assertEqual(len(values), 3)
    self.assertEqual(values[0], 'level2')
    self.assertEqual(values[1], 'level2_new')

    values = self.set_manager.GetUniqueValues(3)
    self.assertEqual(len(values), 4)
    self.assertEqual(values[0], 'level3')
    self.assertEqual(values[1], 'level3_new')

    self.assertEqual(self.set_manager.IsSetEmpty(1), False)
    self.assertEqual(self.set_manager.IsSetEmpty(2), False)
    self.assertEqual(self.set_manager.IsSetEmpty(3), False)


def main(unused_argv):
  unittest.main()
